{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "5c5998db",
   "metadata": {},
   "source": [
    "---\n",
    "* 日期：2022-11-2\\week11（周三）\n",
    "* 课程：python\n",
    "* 记录人：zeng\n",
    "---"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "4d565f35",
   "metadata": {},
   "source": [
    "# 本周学习内容\n",
    "> 1. 元组\n",
    "> 2. 集合\n",
    "> 3. 字典"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "e961777c",
   "metadata": {},
   "source": [
    "## 1. 元组（yuple)\n",
    ">> 1. 元组的概念和基本形态\n",
    ">> 2. 元组的方法"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "659c36ec",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(1800001, 1800002, 1800003) <class 'tuple'>\n"
     ]
    }
   ],
   "source": [
    "user_info = 1800001,1800002,1800003\n",
    "print(user_info,type(user_info))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "c877505e",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1800001\n",
      "[1800001, 1800002]\n"
     ]
    }
   ],
   "source": [
    "# 取值\n",
    "print(user_info[0])\n",
    "# 切片\n",
    "print(user_info[:2])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "d31dc9b5",
   "metadata": {},
   "outputs": [],
   "source": [
    "import time"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "796ddf5c",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "time.struct_time(tm_year=2022, tm_mon=11, tm_mday=2, tm_hour=19, tm_min=18, tm_sec=4, tm_wday=2, tm_yday=306, tm_isdst=0)"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "time.localtime()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "id": "5203ad12",
   "metadata": {},
   "outputs": [],
   "source": [
    "# help(time.localtime())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "92530d2d",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1667387885.5562618"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "time.time() # 时间戳，可以记录互联网中所有数据信息产生、销毁、创建一系列行为"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "92a8ff38",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "user_info.count(1800001)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "352d3d93",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "user_info.index(1800001)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "2f8d24c6",
   "metadata": {},
   "source": [
    "## 2. 集合\n",
    "> 1. 集合的概念和性质\n",
    ">> 1. 集合的唯一性\n",
    ">> 2. 集合的无序性\n",
    "> 2. 集合的方法\n",
    ">> 1. 交集：逻辑运算符： setA & setB , setA,intersection(B)\n",
    ">> 2. 并集：逻辑运算符： setA | setB , "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "id": "76e39364",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'apple', 'orange', 'banana', 'pear'} <class 'set'>\n"
     ]
    }
   ],
   "source": [
    "basket = {'apple','orange','apple','pear','banana'}\n",
    "print(basket,type(basket))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "id": "3ddb6806",
   "metadata": {},
   "outputs": [],
   "source": [
    "舞蹈社_user_id = {211011,211012,211013,211014}\n",
    "合唱团_user_id = {211013,211014,211822,211833}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "id": "8ec5c9ac",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{211013, 211014}"
      ]
     },
     "execution_count": 27,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "舞蹈社_user_id.intersection(合唱团_user_id)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "id": "d8a0526f",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "8"
      ]
     },
     "execution_count": 28,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "len(舞蹈社_user_id) + len(合唱团_user_id)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "id": "c718046c",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "6"
      ]
     },
     "execution_count": 29,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "len(舞蹈社_user_id | 合唱团_user_id)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "18ff7f7b",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "id": "d85ce078",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 思考：如果是列表的话,想要找出重复的项？集合的价值\n",
    "舞蹈社_user_id = {211011,211012,211013,211014}\n",
    "合唱团_user_id = {211013,211014,211822,211833}"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "b832e668",
   "metadata": {},
   "source": [
    "## 3. 字典（dict）\n",
    "> 1. 字典的概念和性质\n",
    ">> 1. 性质：\n",
    ">>> 1. 无序性\n",
    ">>> 2. key是唯一的(没有重复)\n",
    ">>> 3. key是不可变的\n",
    "\n",
    "> 2. 字典的创建\n",
    "```\n",
    "网新1班 = {\n",
    "    211011:\"李华\",\n",
    "    211012:\"小米\",\n",
    "    211013:\"JACK\",\n",
    "    211014:\"MARRY\"\n",
    "}\n",
    "```\n",
    ">>> 2. 使用dict()方法创建字典\n",
    "```\n",
    "网新2班 = dict (\n",
    "    stu211011 = \"李华\",\n",
    "    stu211012 = \"小米\",\n",
    "    stu211013 = \"JACK\",\n",
    "    stu211014 = \"MARRY\"\n",
    ")\n",
    "```\n",
    "> 3. 字典的方法"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 55,
   "id": "244c02a1",
   "metadata": {},
   "outputs": [],
   "source": [
    "wechat = {\n",
    "    \"asdfgh\":[\"AzEng\",\"爱尔兰\",\"女\",\"158\",\"置顶聊天\",\"会话\"],\n",
    "    \"zxcvb\":[\"Jack\",\"香港\"]\n",
    "}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 56,
   "id": "20634127",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['AzEng', '爱尔兰', '女', '158', '置顶聊天', '会话']"
      ]
     },
     "execution_count": 56,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "wechat[\"asdfgh\"]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 57,
   "id": "3bbdfe17",
   "metadata": {},
   "outputs": [],
   "source": [
    "网新1班 = {\n",
    "    211011:\"李华\",\n",
    "    211012:\"小米\",\n",
    "    211013:\"JACK\",\n",
    "    211014:\"MARRY\"\n",
    "}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 58,
   "id": "c958135b",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{211011: '李华', 211012: '小米', 211013: 'JACK', 211014: 'MARRY'} <class 'dict'>\n"
     ]
    }
   ],
   "source": [
    "print(网新1班,type(网新1班))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 59,
   "id": "7c960491",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'小米'"
      ]
     },
     "execution_count": 59,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "网新1班[211012]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 60,
   "id": "108e4ee8",
   "metadata": {},
   "outputs": [],
   "source": [
    "网新2班 = dict (\n",
    "    stu211011 = \"李华\",\n",
    "    stu211012 = \"小米\",\n",
    "    stu211013 = \"JACK\",\n",
    "    stu211014 = \"MARRY\"\n",
    ")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 61,
   "id": "6d5255b2",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'李华'"
      ]
     },
     "execution_count": 61,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "网新2班[\"stu211011\"]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "5f3f0efc",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "markdown",
   "id": "607fb218",
   "metadata": {},
   "source": [
    "## 预习字典的方法"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.7"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
